{extend name="public:base"/}
{block name="main"}
<style type="text/css">
  .width-250{width:250px !important; }

</style>
<div class="layui-row">
    <form class="layui-form" action="" method="POST">
       <div class="layui-col-md9" style="border-right:1px solid #eee;padding-right:10px;">
          <center><h2>基本设置</h2></center>
          <hr/>
          <div class="layui-form-item">
              <label class="layui-form-label"><span class="form-required">*</span>选择分类</label>
              <div class="layui-input-inline"  >
                 <select name="cateid" lay-verify="required" lay-filter="select">
                  <option value="">请选择分类</option>
                    {notempty name="catelist"}
                    {foreach $catelist as $v}
                    <option value="{$v['cateid']}" {if condition="$info['cateid'] eq $v['cateid'] "}selected="selected"{/if}>{$v['catename']}</option>
                    {/foreach}
                    {/notempty}
                </select>  
              </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label"><span class="form-required">*</span>文章标题</label>
            <div class="layui-input-block">
            	<input type="hidden" name="newsid" value="{$info['newsid']}">
              <input type="text" name="title" required lay-verify="required" placeholder="请输入标题"  class="layui-input" value="{$info['title']}">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">seo文章关键字</label>
            <div class="layui-input-block">
              <input type="text" name="keyword"  placeholder="请输入文章关键字" autocomplete="off" class="layui-input"  value="{$info['keyword']}">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">seo文章描述</label>
            <div class="layui-input-block">
              <input type="text" name="description"  placeholder="请输入文章描述" autocomplete="off" class="layui-input"  value="{$info['description']}">
            </div>
          </div>
          
          <div class="layui-form-item">
            <label class="layui-form-label">封面图片</label>
            <div class="layui-input-inline" >
              <input type="text" name="thumb"  placeholder="图片地址" autocomplete="off" class="layui-input"  value="{$info['thumb']}">
            </div>
            <div class="layui-form-mid layui-word-aux" style="padding-top: 0px !important; ">
              {notempty name="info['thumb']"}
              <img src="{$info['thumb']}" id="thumb" class="content-photos">
              {/notempty}
              <button type="button" class="layui-btn layui-btn-small layui-btn-normal thumbupload" lay-data="{data:{type:'image'},accept:'images'}" data-name="thumb" style="margin-left:10px;">
                <i class="layui-icon">&#xe64a;</i>上传图片
              </button>
            </div>
          </div>
          <div class="layui-form-item layui-form-text">
              <label class="layui-form-label">文章摘要</label>
              <div class="layui-input-block">
                  <textarea name="abstract" placeholder="请输入文章摘要" class="layui-textarea">{$info['abstract']}</textarea>
              </div>
          </div>
          <div class="layui-form-item layui-form-text">
      		    <label class="layui-form-label">文章内容</label>
      		    <div class="layui-input-block" style="max-width:100%;">
               {tag:Uedit name='content' id="myEditors" data="htmlspecialchars_decode($info['content'])"/} 

              
      		    <p><input type="checkbox"  title="设定内容第一张图片为封面" lay-skin="primary" lay-filter="gethumb"></p>
              </div>
      		</div>
          <div class="layui-form-item">
          <label class="layui-form-label">跳转链接</label>
          <div class="layui-input-block">
            <input type="text" name="url" requplaceholder="请输入跳转链接" autocomplete="off" class="layui-input" value="{$info['url']}" placeholder="请输入跳转链接">
          </div>
        </div>
          <div class="layui-form-item">
            <label class="layui-form-label">相册</label>
            <div class="layui-form-mid layui-word-aux" style="padding-top: 0px !important; ">
              <button type="button" class="layui-btn layui-btn-small layui-btn-normal photosload" lay-data="{data:{type:'image'},accept:'images'}" data-name="photos">
                <i class="layui-icon">&#xe60d;</i>上传相册
              </button>
            </div>
          </div>
           <div class="layui-form-item" id="PhotosDom">
          {notempty name="info['photos']"}
              {foreach $info['photos']['name'] as $k=>$v}

                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="photos[name][]" lay-verify="required" placeholder="图片名称" autocomplete="off" class="layui-input" placeholder="文件名称" value="{$info['photos']['name'][$k]}">
                    <input type="hidden" name="photos[path][]" placeholder="图片地址"></div>
                    <img src="{$info['photos']['path'][$k]}" class="content-photos" value="{$info['photos']['path'][$k]}">
                    <button type="button" class="layui-btn layui-btn-danger layui-btn-xs" onclick="deldom(this)">删除</button>
                </div>

              {/foreach}
          {/notempty}
          </div>
        
          <div class="layui-form-item">
            <label class="layui-form-label">附件</label>
            <div class="layui-form-mid layui-word-aux" style="padding-top: 0px !important; ">
              <button  type="button" class="layui-btn layui-btn-small layui-btn-normal filesupload" lay-data="{data:{type:'file'},accept:'file'}" data-name="file">
                <i class="layui-icon">&#xe61d;</i>上传附件
              </button>
              
            </div>
            <div class="layui-form-item" id="filedata" >
                {notempty name="info['files']"}
                {foreach $info['files']['name'] as  $k=>$v}
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <input type="hidden" name="files[src][]" value="{$info['files']['src'][$k]}">
                    <input type="hidden" name="files[name][]" value="{$info['files']['name'][$k]}">
                    <a href="{$info['files']['src'][$k]}" target="_blank">{$info['files']['name'][$k]}</a>&nbsp;&nbsp;
                    <a href="javascript:deldom(this);">删除</a>
                </div>
                {/foreach}
                {/notempty}
            </div>
          </div>
          </div>
          <div class="layui-col-md3" >
            <center><h2>其他设置</h2></center>
            <hr/>
            <div class="layui-form-item">
                <label class="layui-form-label">选择作者</label>
                <div class="layui-input-inline"   lay-filter="author">
                   <select name="authorid" id="author">
                   <option value="">请选择作者</option>
                   {if condition="$info['authorid'] eq ''"}
                    
                      {notempty name="authorlist"}
                      {foreach $authorlist as $v}
                      <option value="{$v['authorid']}" {if condition="$modelinfo['authorid'] eq $v['authorid'] "}selected="selected"{/if}>{$v['name']}</option>
                      {/foreach}
                      {/notempty}
                    {else/}
                      {notempty name="authorlist"}
                      {foreach $authorlist as $v}
                      <option value="{$v['authorid']}" {if condition="$info['authorid'] eq $v['authorid'] "}selected="selected"{/if}>{$v['name']}</option>
                      {/foreach}
                      {/notempty}
                    {/if}
                  </select>  
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择模板</label>
                <div class="layui-input-inline"  >
                   <select name="template" id="template" lay-filter="template" >
                   <option value="">请选择模板</option>
                    
                    {notempty name="pages"}
                      {foreach $pages as $v}
                      <option value="{$v}" {if condition="$info['template'] eq $v "}selected="selected"{/if}>{$v}.html</option>
                      {/foreach}
                    {/notempty}
                   
                  </select>  
                </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">发布时间</label>
              <div class="layui-input-inline">
                <input type="text" name="pushtime"  placeholder="定时发布时间"  class="layui-input" value="{$info['pushtime']}" id="pushtime">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">状态</label>
              <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="上架" {if condition=" ($info['status'] eq '') or ($info['status'] eq '1')"}checked{/if}>
                <input type="radio" name="status" value="0" title="下架" {eq name="info['status']" value="0"}checked{/eq}>
                <input type="radio" name="status" value="-1" title="草稿" {eq name="info['status']" value="-1"}checked{/eq}>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">评论</label>
              <div class="layui-input-block" lay-filter="iscomment">
                {if condition="$info['newsid'] eq ''"}
                  <input type="radio" name="iscomment" value="1" title="启用" {neq name="modelinfo['iscomment']" value="0"}checked{/neq} >
                  <input type="radio" name="iscomment" value="0" title="禁用" {eq name="modelinfo['iscomment']" value="0"}checked{/eq}>
                {else/}
                  <input type="radio" name="iscomment" value="1" title="启用" {neq name="info['iscomment']" value="0"}checked{/neq} >
                  <input type="radio" name="iscomment" value="0" title="禁用" {eq name="info['iscomment']" value="0"}checked{/eq} >
                {/if}
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">其他</label>
              <div class="layui-input-block">
                <input type="checkbox" name="hot" title="推荐" {eq name="info['hot']" value="1"}checked{/eq}>
                <input type="checkbox" name="top" title="置顶" {eq name="info['top']" value="1"}checked{/eq}>
              </div>
            </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
          </div>
        </div>
    </form>
</div>
<script type="text/javascript">
	layui.use(['form','layedit','upload','laydate'], function(){
	  var form = layui.form
	  ,layedit = layui.layedit
    ,upload  = layui.upload
    ,laydate = layui.laydate;
	  

    laydate.render({
      elem: '#pushtime',
      type: 'datetime'
    });

    /*缩略图上传*/
    upload.render({
      elem: '.thumbupload' //绑定元素
      ,url: '{:Url('common/fileupload',array('other'=>'newinfo'))}' //上传接口
      ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。

        layer.load(); //上传loading
      }
      ,done: function(res,index){ 

          layer.closeAll('loading');

          if(res.status=='1'){ 

              $("#thumb").remove();

              var item = this.item;

              var dom=item.attr('data-name');
              $("input[name='"+dom+"']").val(res.path);
              $(item).before('<img src="'+res.path+'" id="thumb" class="content-photos">');

          }else{
            alert("上传失败,请重试！");
          }
      }
      ,error: function(){
          layer.closeAll('loading');
          alert("上传失败,请重试！");
        //请求异常回调
      }
      ,field:'file' //字段名

    });
    /*相册*/
    upload.render({
      elem: '.photosload' //绑定元素
      ,url: '{:Url('common/fileupload',array('other'=>'newinfo'))}' //上传接口
      ,multiple: true  //多文件上传
      ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
        //console.log(obj);
        layer.load(); //上传loading
      }
      ,done: function(res,index){ 

          layer.closeAll('loading');

          if(res.status=='1'){
            
              var item = this.item;

             /* var html="<div class='layui-inline'><label class='layui-form-label'></label><div class='layui-input-inline' style='width: 100px;'><input type='text' name='photos[name][]' lay-verify='required' placeholder='图片名称' autocomplete='off' class='layui-input' placeholder='文件名称' value="'+res.filename+'"><input type='hidden' name='photos[file][]' value="'+res.path+'" placeholder='图片地址'></div><img src="'+res.path+'" class='content-photos'><button type='button' class='layui-btn layui-btn-danger layui-btn-xs' onclick='deldom(this)'>删除</button></div><br/>";*/

              var html='<div class="layui-form-item"><label class="layui-form-label"></label><div class="layui-input-inline" style="width: 100px;"><input type="text" name="photos[name][]" lay-verify="required" placeholder="图片名称" autocomplete="off" class="layui-input" placeholder="文件名称" value="'+res.filename+'"><input type="hidden" name="photos[path][]" value="'+res.path+'" placeholder="图片地址"></div><img src="'+res.path+'" class="content-photos"><button type="button" class="layui-btn layui-btn-danger layui-btn-xs" onclick="deldom(this)">删除</button></div>';

              $("#PhotosDom").append(html);

              /*var dom=item.attr('data-name');
              layui.$("input[name='"+dom+"']").val(res.path);*/

          }else{
            alert("上传失败,请重试！");
          }
      }
      ,error: function(){
          layer.closeAll('loading');
          alert("上传失败,请重试！");
        //请求异常回调
      }
      ,field:'file' //字段名

    });

    /*附件*/
    upload.render({
      elem: '.filesupload' //绑定元素
      ,url: '{:Url('common/fileupload')}' //上传接口
      ,multiple: false  //多文件上传
      ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
        //console.log(obj);
        layer.load(); //上传loading
      }
      ,done: function(res,index){ 

          layer.closeAll('loading');

          if(res.status=='1'){

              var html='<input type="hidden" name="files[src][]" value="'+res.path+'"><input type="hidden" name="files[name][]" value="'+res.filename+'"><a href="'+res.path+'" target="_blank">'+res.filename+'</a>&nbsp;&nbsp;<a href="javascript:deldom(this);">删除</a>';

              $("#filedata").append(html);


          }else{
            alert("上传失败,请重试！");
          }
      }
      ,error: function(){
          layer.closeAll('loading');
          alert("上传失败,请重试！");
        //请求异常回调
      }
      ,field:'file' //字段名

    });


    {notempty name="info"}
    
      layui.$("select[name='cateid']").val({$info['cateid']});
      layui.form.render('select')
    {/notempty}


    form.on('checkbox(gethumb)', function(data){
      if(data.elem.checked==true){
          var text=UM.getEditor('myEditors').getPlainTxt();
        
          var src=(text.match('src="(.*?)"')[1]);
          if(src){
            $("input[name='thumb']").val(src);
            $("#thumb").remove();
            $("input[name='thumb']").parents(".layui-form-item").prepend('<img src="'+src+'" id="thumb" class="content-photos">');
          }
      }
    }); 


    form.on('select(select)', function(data){
      $("input[name='url']").val("");
      
      $.get(location.href,{cateid:data.value},function(data){
        if(data.code=='0'){
          alert(data.msg);
        }else{
            $("#template").html("<option value=''>请选择模板</option>");
            $.each(data.msg.pages,function(k,v){
              $("#template").append("<option value='"+v+"'>"+v+".html</option>");
            });

            $("#template").val(data.msg.modelinfo.content);
            $("#author").val(data.msg.modelinfo.authorid);

            $(":radio[name='iscomment'][value='"+data.msg.modelinfo.iscomment+"']").attr("checked","checked");  

            form.render('select'); 
            form.render('radio'); 

        }
      },'json');

    }); 

    layer.photos({
      photos: 'div'
      ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    }); 
    

	});

  function deldom($this,type){
      layer.confirm('确定清除这个图片吗？', function(index){
        var sthis=$($this).parent(".layui-form-item");
        
        {if condition="config('site.file_del' eq '1')"}
        var src=sthis.find("img").attr("src");
        $.post("{:url('common/removefile')}",{"file":src},function(){});
        {/if}
        
        //清除img dom
        sthis.remove();
        
        layer.close(index);
      });  
  }


</script>



{/block}